
#include "vroute_sys_control.hpp"
#include "vrouteErrors.hpp"
#include "vroute_sys_statu.hpp"
#include "vroute_sys.hpp"
#include "vroute_data_in_outter.hpp"
#include "stackProtocol.hpp"
#include "vroute_deviceInfoMgr.hpp"

using namespace vroute_stack;

int startServer(SystemStartType type)
{
    assert(nullptr != CSysCtrl::getInstance());
    return CSysCtrl::getInstance()->startServer(type);
}

int stopServer(SystemStopType type)
{
    assert(nullptr != CSysCtrl::getInstance());
    return CSysCtrl::getInstance()->stopServer(type);
}

int getState(SystemStatueType type, void* param)
{
    assert(nullptr != CSysStatu::getInstance());
    CSysStatu::getInstance()->getStatu(type, param);
    return sys_stu_type_running;
}

int dataOut(char* content, int len, int sockIndex)
{
    vos_sleep(100);
    return 0;
}

int dataIn(char* content, int len, int socketIndex)
{
    return CDataInOutter::getInstance()->dataIn(content, len, socketIndex);
}

int getHeaderLen()
{
    return default_dataprotocol_header_len;
}

int getPacketLeftLen(char* content)
{
    static CProtocolHeader* _cph = new CProtocolHeader();
    if (content == nullptr)
    {
        return 0;
    }
    return _cph->getTotalLength(content) - getHeaderLen();
}

int setLocalInfo(vroute_stack::LocalInfo* dvinfo)
{
    return CDevMgr::getInstance()->setDevInfo(dvinfo);
}

unsigned int convertAddr(char* unique)
{
    return CTools::getCompAddr(unique);
}
